#include <windows.h>
#include <wininet.h>
#include <stdarg.h>
#include <intrin.h>
#include <stdbool.h>

#define HOSTNAME TEXT("www.baidu.com")
#define URLPATH TEXT("/")

void mainCRTStartup()
{
    HINTERNET hOpen = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    HINTERNET hConnect = InternetConnect(hOpen, HOSTNAME, INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
    HINTERNET hRequest = HttpOpenRequest(hConnect, NULL, URLPATH, NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD dwSize = 0;
    HttpSendRequestW(hRequest, NULL, 0, NULL, 0);
    do
    {
        DWORD i;
        char buf[0x100];
        InternetQueryDataAvailable(hRequest, &dwSize, 0, 0);
        for (i = 0; i < dwSize; i += 0x100)
        {
            DWORD dwRead = 0;
            InternetReadFile(hRequest, buf, 0x100, &dwRead);
            WriteConsoleA(hStdOut, buf, dwRead, NULL, NULL);
        }
    } while (dwSize);
    InternetCloseHandle(hRequest);
    InternetCloseHandle(hConnect);
    InternetCloseHandle(hOpen);
    ExitProcess(0);
}